/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef TIMERINSTRUCTIONLOGIC_H
#define TIMERINSTRUCTIONLOGIC_H
#include "timerinstruction.h"
#include "programset.h"
#include "instructionEnum.h"
#include "robotio.h"
#include  "regdata.h"


class ProgramEngine;
/**
 * @brief The TimerInstructionLogic class  指令逻辑处理类
 */
class TimerInstructionLogic
{
public:
    TimerInstructionLogic(int robotIdIn,ProgramSet* programSetIn,RobotIo* ioControllerIn,
                          ProgramEngine* programEngineIn,RegData *regDataIn);

public:
    /**
     * @brief startTimerCmd
     * @param programNum
     * @param timerInstruct
     * @return
     */
    E_PROGRAM_LOOP_RESULT startTimerCmd(int programNum,TimerInstruction timerInstruct);

    bool countWaitTime(float waitTime);
    int reset();

private:

    /**
     * @brief addMsg  , 添加消息反馈
     * @param messageLevel
     * @param componentName
     * @param messageType
     * @param messageCode
     * @param robotId
     * @param parameter1
     * @param parameter2
     * @param parameter3
     * @param parameter4
     */
    void addMsg( int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 int parameter1 = 0,
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0,
                 QString message= "");

private:
    int robotId;
    ProgramSet* programSet;
    RobotIo* ioController;
    ProgramEngine* programEngine;
    /**
     * @brief regData           寄存器数据
     */
    RegData *regData;


    bool waitTimeStartFlag;

    struct timeval waitStartTime,waitEndTime;

    struct timeval startTime,endTime;
};

#endif // TIMERINSTRUCTIONLOGIC_H
